<?php
// 支付宝生成支付数据

// 订单数据
require_once $this->website['path']['action'] . '/app/pay/data.php';
// 以下是 data.php 中的变量
// $json
// $title       ---商品名称
// $totals      ---支付总价
// $orderCode   ---订单号
// $orderid     ---所有订单号
// $num         ---订单个数---判断是否是多个订单一起支付

require_once $this->website['path']['lib'] . '/ali/pay/AopCertClient.php';
require_once $this->website['path']['lib'] . '/ali/pay/request/AlipayTradeAppPayRequest.php';

$configura = fn_configura($this->website, 'sys');

$arr = array(
	'total_amount' => '' . bcdiv($totals, 100, 2),
	'subject' => $title,
	'body' => $title,
	'timeout_express' => '30m',
	'product_code' => 'QUICK_MSECURITY_PAY',
	'out_trade_no' => "{$orderCode}",
	'passback_params' => urlencode(json_encode($orderid)),
);

$aop = new AopCertClient;
// "应用证书路径（要确保证书文件可读），例如：/home/admin/cert/appCertPublicKey.crt";
$appCertPath = $this->website['path']['conf'] . '/crt/ali/appCertPublicKey_2021001164698990.crt';
//"支付宝公钥证书路径（要确保证书文件可读），例如：/home/admin/cert/alipayCertPublicKey_RSA2.crt";
$alipayCertPath = $this->website['path']['conf'] . '/crt/ali/alipayCertPublicKey_RSA2.crt';
// "支付宝根证书路径（要确保证书文件可读），例如：/home/admin/cert/alipayRootCert.crt";
$rootCertPath = $this->website['path']['conf'] . '/crt/ali/alipayRootCert.crt';

$aop->gatewayUrl = "https://openapi.alipay.com/gateway.do";
$aop->appId = $configura['payAppidZfb'];
// '请填写开发者私钥去头去尾去回车，一行字符串' ;
$aop->rsaPrivateKey = file_get_contents($this->website['path']['conf'] . '/crt/ali/ujiabaobei.com.private.crt');
$aop->format = "json";
$aop->charset = "UTF-8";
$aop->signType = "RSA2";

//调用getPublicKey从支付宝公钥证书中提取公钥
$aop->alipayrsaPublicKey = $aop->getPublicKey($alipayCertPath);
//是否校验自动下载的支付宝公钥证书，如果开启校验要保证支付宝根证书在有效期内
$aop->isCheckAlipayPublicCert = true;
//调用getCertSN获取证书序列号
$aop->appCertSN = $aop->getCertSN($appCertPath);
//调用getRootCertSN获取支付宝根证书序列号
$aop->alipayRootCertSN = $aop->getRootCertSN($rootCertPath);

//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称：alipay.trade.app.pay
$request = new AlipayTradeAppPayRequest();
//SDK已经封装掉了公共参数，这里只需要传入业务参数
// $request->setBizContent("{\"body\":\"我是测试数据\","
// 	. "\"subject\": \"App支付测试\","
// 	. "\"out_trade_no\": \"20170125test01\","
// 	. "\"timeout_express\": \"30m\","
// 	. "\"total_amount\": \"0.01\","
// 	. "\"product_code\":\"QUICK_MSECURITY_PAY\""
// 	. "}");
$request->setBizContent(json_encode($arr));
$request->setNotifyUrl($configura['payZfbNotifyUrl']);
//这里和普通的接口调用不同，使用的是sdkExecute
$response = $aop->sdkExecute($request);

$json['data'] = $response;

$json['status'] = 'ok';

$this->json_encode_encrypt($json);
